﻿using HalconDotNet;
using Halcon二次开发.Controller.中心距合格检测;
using Halcon二次开发.Controller.卡尺;
using Halcon二次开发.Controller.多文本显示;
using Halcon二次开发.Controller.结果分析工具;
using Halcon二次开发.Controller.角度合格检测;
using Halcon二次开发.Controller.距离转换工具;
using Halcon二次开发.Model.自定义控件;
using Halcon二次开发.View.卡尺;
using Halcon二次开发.View.多文本显示工具;
using Halcon二次开发.View.精准测量模块;
using Halcon二次开发.View.结果分析工具;
using Halcon二次开发.View.角度界面;
using Halcon二次开发.View.距离转换工具;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Halcon二次开发.Controller.精准测量模块功能
{
    public class CaliperModuleController
    {
        public HObject HideIntputImage;
        public double[] HideIntputArrayRows;
        public double[] HideIntputArrayColumns;
        public double[] HideIntputArrayPhis;
        private CaliperModuleForm form;

        public HwindowFlowNodeUrseControl hwindowFlowNode;
        public CaliperModuleController(CaliperModuleForm caliperModuleForm, HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.form = caliperModuleForm;
            this.hwindowFlowNode = hwindowFlowNode; 
        }

        public CaliperModuleController()
        {
        }

        public void Run()
        {
            CaliperRun();
            DistanceRun();
            AnalyseRun();
            MessageRun();
            
            AnagleRun();
            DistanceSRun();
            BlodRun();
        }
        /// <summary>
        /// 初始化，添加节点时赋值
        /// </summary>
        /// <param name="HideIntputArrayRows"></param>
        /// <param name="HideIntputArrayColumns"></param>
        /// <param name="HideIntputArrayPhis"></param>
        /// <param name="HideIntputImage"></param>
        public void DataTransfer()
        {
            //卡尺工具
            this.form.caliperForm.controller.HideIntputArrayRows = HideIntputArrayRows;
            this.form.caliperForm.controller.HideIntputArrayColumns =HideIntputArrayColumns;
            this.form.caliperForm.controller.HideIntputArrayPhis = HideIntputArrayPhis;
            this.form.caliperForm.controller.HideIntputImage =HideIntputImage;

            //距离转换
            this.form.distanceForm.controller.HideIntputArrayDistances = this.form.caliperForm.controller.HideOutputArrayDistances;

            //结果分析
            this.form.analyseForm.controller.HideIntputArrays.Clear();
            if (this.form.distanceForm.controller.HideOutputArrayDistances != null)
            {
                this.form.analyseForm.controller.HideIntputArrays.AddRange(this.form.distanceForm.controller.HideOutputArrayDistances);
            }
            //文本显示
            this.form.messageForm.controller.HideIntputImage = HideIntputImage;
            this.form.messageForm.controller.HideIntputArrayRows = this.form.caliperForm.controller.HideOutputArrayRows;
            this.form.messageForm.controller.HideIntputArrayColumns = this.form.caliperForm.controller.HideOutputArrayColumns;
            this.form.messageForm.controller.HideIntputArrayDistances = this.form.distanceForm.controller.HideIntputArrayDistances;
            this.form.messageForm.controller.HideIntputResults = this.form.analyseForm.controller.HideOutputResults;

            //角度测量
            this.form.anagleForm.controller.HideIntputArrayRows = this.HideIntputArrayRows;
            this.form.anagleForm.controller.HideIntputArrayColumns = this.HideIntputArrayColumns;
            this.form.anagleForm.controller.HideIntputArrayPhis = this.HideIntputArrayPhis;
            this.form.anagleForm.controller.HideIntputImage = this.HideIntputImage;

            //中心距
            this.form.distansceForm.controller.linesList= this.form.caliperForm.controller.linesList;
            this.form.distansceForm.controller.HideIntputImage = this.HideIntputImage;
            this.form.distansceForm.controller.Sum3 = this.form.distanceForm.controller.Sum3;


            //瑕疵检测
            this.form.boldForm.controller.HideIntputImage = HideIntputImage;
            this.form.boldForm.controller.HideIntputArrayRows = HideIntputArrayRows;
            this.form.boldForm.controller.HideIntputArrayColumns = HideIntputArrayColumns;
            this.form.boldForm.controller.HideIntputArrayPhis = HideIntputArrayPhis;
        }

        public void CaliperRun()
        {
            this.form.caliperForm.controller.HideIntputArrayRows = this.HideIntputArrayRows;
            this.form.caliperForm.controller.HideIntputArrayColumns = this.HideIntputArrayColumns;
            this.form.caliperForm.controller.HideIntputArrayPhis = this.HideIntputArrayPhis;
            this.form.caliperForm.controller.HideIntputImage = this.HideIntputImage;
            this.form.caliperForm.controller.Run();
        }
        /// <summary>
        /// 距离转换运行
        /// </summary>
        /// <param name="HideOutputArrayDistances"></param>
        public void DistanceRun()
        {
            //距离转换
            this.form.distanceForm.controller.HideIntputArrayDistances = this.form.caliperForm.controller.HideOutputArrayDistances;
            this.form.distanceForm.controller.Run();
        }
        /// <summary>
        /// 结果分析运行
        /// </summary>
        public void AnalyseRun()
        {
            //结果分析
            this.form.analyseForm.controller.HideIntputArrays.Clear();
            this.form.analyseForm.controller.HideIntputArrays.AddRange(this.form.distanceForm.controller.HideOutputArrayDistances);
            if (this.form.analyseForm.comboBox1.Text.Trim() == "打开")
            {
                this.form.analyseForm.controller.Run();

            }
        }
        /// <summary>
        /// 文本显示分析
        /// </summary>
        public void MessageRun()
        {
            //文本显示
            this.form.messageForm.controller.HideIntputImage = this.HideIntputImage;
            this.form.messageForm.controller.HideIntputArrayRows = this.form.caliperForm.controller.HideOutputArrayRows;
            this.form.messageForm.controller.HideIntputArrayColumns = this.form.caliperForm.controller.HideOutputArrayColumns;
            this.form.messageForm.controller.HideIntputArrayDistances = this.form.distanceForm.controller.HideOutputArrayDistances;
            this.form.messageForm.controller.HideIntputResults = this.form.analyseForm.controller.HideOutputResults;

            if (this.form.analyseForm.comboBox1.Text.Trim() == "关闭")
            {
                this.form.messageForm.controller.HideIntputResults.Clear();

            }

            if (this.form.messageForm.comboBox4.Text.Trim() == "打开")
            {
                this.form.messageForm.controller.Run();
            }
        }
        /// <summary>
        /// 角度测量运行
        /// </summary>
        public void AnagleRun()
        {
            //角度测量
            this.form.anagleForm.controller.HideIntputArrayRows = this.HideIntputArrayRows;
            this.form.anagleForm.controller.HideIntputArrayColumns = this.HideIntputArrayColumns;
            this.form.anagleForm.controller.HideIntputArrayPhis = this.HideIntputArrayPhis;
            this.form.anagleForm.controller.HideIntputImage = this.HideIntputImage;
            if (this.form.anagleForm.comboBox1.Text.Trim() == "打开")
            {
                this.form.anagleForm.controller.Run();
            }
        }
        /// <summary>
        /// 中心距运行
        /// </summary>
        private void DistanceSRun()
        {
            //中心距
            this.form.distansceForm.controller.linesList = this.form.caliperForm.controller.linesList;
            this.form.distansceForm.controller.HideIntputImage = this.HideIntputImage;
            this.form.distansceForm.controller.Sum3 = this.form.distanceForm.controller.Sum3;
            if (this.form.distansceForm.comboBox1.Text.Trim() == "打开")
            {
                this.form.distansceForm.controller.Run();
            }
        }
        /// <summary>
        /// 瑕疵分析
        /// </summary>
        public void BlodRun() {
            this.form.boldForm.controller.HideIntputImage = this.HideIntputImage;
            this.form.boldForm.controller.HideIntputArrayRows = this.HideIntputArrayRows;
            this.form.boldForm.controller.HideIntputArrayColumns = this.HideIntputArrayColumns;
            this.form.boldForm.controller.HideIntputArrayPhis = this.HideIntputArrayPhis;
            this.form.boldForm.controller.Run(0);
        }
        /// <summary>
        /// 并发执行卡尺测量工具
        /// </summary>
        public void HardRunCailper(HSmartWindowControl hSmartWindowControl, HObject HideIntputImage, double[] IntputRows, double[] IntputAngles, double[] IntputColums, PreciseCaliper form, string[] strdb, double HideIntputSigma, double HideIntputThreshold, ref double[,] linesList, ref double[] HideOutputArrayDistances, ref double[] HideOutputArrayRows, ref double[] HideOutputArrayColumns, HTuple[] line1Place, HTuple[] line2Place, List<double> line1counterFrist, List<double> line2counterFrist)
        {

            Caliper controller = new Caliper();
            controller.HardRun(hSmartWindowControl,HideIntputImage,IntputRows,IntputAngles,IntputColums,form,strdb,HideIntputSigma,HideIntputThreshold, ref linesList,ref HideOutputArrayDistances,ref HideOutputArrayRows,ref HideOutputArrayColumns,line1Place,line2Place,line1counterFrist,line2counterFrist);
        }
        /// <summary>
        /// 并发执行距离转换工具
        /// </summary>
        public void HardRunDistance(DistanceToolForm distanceToolForm, double[] HideIntputArrayDistances, ref double[] HideOutputArrayDistances)
        {
            DistanceToolController distanceToolControlle = new DistanceToolController();
            distanceToolControlle.HardRun(distanceToolForm, HideIntputArrayDistances, ref HideOutputArrayDistances);
        }
        /// <summary>
        /// 并发执行结果分析工具
        /// </summary>
        public void HardRunAnalyse(AnalyseResultForms analyseResultForms, List<double> HideIntputArrays, ref List<bool> HideOutputResults)
        {
            AnalyseControl analyseControl = new AnalyseControl();
            analyseControl.HardRun(analyseResultForms,HideIntputArrays,ref HideOutputResults);
        }  
        /// <summary>
        /// 并发执行文本显示工具
        /// </summary>
        public void HardRunMessage(MessageBoxStringsForms form, double[] HideIntputArrayRows, double[] HideIntputArrayColumns, HSmartWindowControl hSmartWindowControl, double[] HideIntputArrayDistances, List<bool> HideIntputResults)
        {
            ShowTextController showTextController = new ShowTextController();
            showTextController.HardRun(form,HideIntputArrayRows,HideIntputArrayColumns,hSmartWindowControl,HideIntputArrayDistances, HideIntputResults);
        }
        /// <summary>
        /// 并发执行角度测量工具
        /// </summary>
        public void HardRunAnagleRune(AnagleForm pmaForm, HSmartWindowControl hSmartWindowControl, HTuple startLineRows, HTuple startLineColumns, HObject HideIntputImage, List<double> pointStants, double[] HideIntputArrayRows, double[] HideIntputArrayColumns, double[] HideIntputArrayPhis, ref List<bool> HideOutputResults, HTuple[] attValuesCounterpoint, List<double> counterFrist, ref double angle)
        {
            AngleAction angleAction = new AngleAction();
            angleAction.HardRun(pmaForm,hSmartWindowControl,startLineRows,startLineColumns,HideIntputImage,pointStants,HideIntputArrayRows,HideIntputArrayColumns,HideIntputArrayPhis,ref HideOutputResults,attValuesCounterpoint,counterFrist,ref angle);
        }
        /// <summary>
        /// 并发执行间距测量工具
        /// </summary>
        public void HardRunDistanceS()
        {
            //SpacedetectionController spacedetectionController = new SpacedetectionController();
            //spacedetectionController.HardRun();
        }
        /// <summary>
        /// 并发执行瑕疵检测工具
        /// </summary>
        public void HardRunBlod()
        {

        }
    }
}
